import {
  Column,
  Entity,
  JoinTable,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { Article } from '../../article/entities/article.entity';

@Entity()
export class Comment {
  @PrimaryGeneratedColumn()
  id: string;

  //一个文章有多个评论
  // @Column({ type: 'varchar', comment: '文章id' })
  @ManyToOne(() => Article, (article: Article) => article.comments)
  @JoinTable({
    name: 'article_comment', // 指定中间表的名称
    joinColumn: {
      name: 'commentId',
      referencedColumnName: 'id',
    },
    inverseJoinColumn: {
      name: 'articleId',
      referencedColumnName: 'id',
    },
  })
  article: Article;

  @Column({ type: 'varchar', comment: '用户id' })
  user_id: string;

  @Column({ type: 'varchar', comment: '评论内容' })
  content: string;

  @Column({ type: 'integer', comment: '点赞数' })
  stars: number;

  @Column({ type: 'integer', comment: '父评论id' })
  parent_id: string;

  @Column({
    type: 'datetime',
    default: () => 'CURRENT_TIMESTAMP',
    comment: '创建时间',
  })
  create_time: Date;

  @Column({
    type: 'datetime',
    default: () => 'CURRENT_TIMESTAMP',
    onUpdate: 'CURRENT_TIMESTAMP',
    comment: '更新时间',
  })
  update_time: Date;

  @Column({ type: 'boolean', comment: '是否禁用', default: false })
  is_disabled: boolean;

  @Column({ type: 'boolean', comment: '是否删除', default: false })
  is_deleted: boolean;

  @Column({ type: 'datetime', comment: '禁用时间', default: null })
  disabled_time: Date;

  @Column({ type: 'datetime', comment: '删除时间', default: null })
  delete_time: Date;
}
